package fr.isima.myant;

import java.util.ArrayList;
import java.util.List;

public class Target {
	private String name;
	private List<Target> dependencies;
	private List<Task> tasks;
	
	public Target() {}
	
	public Target(String name) {
		super();
		this.name = name;
		dependencies = new ArrayList<Target>();
		tasks = new ArrayList<Task>();
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public List<Target> getDependencies() {
		return dependencies;
	}
	
	public void addDependency(Target dependency) {
		dependencies.add(dependency);
	}
	
	public List<Task> getTasks() {
		return tasks;
	}
	
	public void addTask(Task task) {
		tasks.add(task);
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		
		sb.append("\tName : " + name + "\n");
		sb.append("\tDependencies : ");
		
		for(Target target : dependencies) {
			sb.append(target.getName() + ", ");
		}
		
		sb.append("\n\tTasks : " + "\n");
		
		for(Task task : tasks) {
			sb.append(task);
		}
		
		sb.append("\n");
		
		return sb.toString();
	}
	
	public void execute(){
		for(Task task : tasks) {
			task.execute();
		}
	}
	
}
